Blockly.defineBlocksWithJsonArray([{
    "type": "dict_null",
    "message0": "建造一个空字典",
    "inputsInline": true,
    "output": "dict",
    "colour": "#a073ff",
    "tooltip": "建造一个空的字典，具体内容可以自己设置。",
    "helpUrl": ""
}, {
    "type": "dict_set",
    "message0": "设置字典 %1 %2 里的 %3 属性为 %4 %5",
    "args0": [
        {
            "type": "input_dummy"
        },
        {
            "type": "input_value",
            "name": "dict",
            "check": "dict"
        },
        {
            "type": "input_value",
            "name": "key",
            "check": "String"
        },
        {
            "type": "input_dummy"
        },
        {
            "type": "input_value",
            "name": "value"
        }
    ],
    "inputsInline": true,
    "previousStatement": null,
    "nextStatement": null,
    "colour": "#a073ff",
    "tooltip": "设置属性。",
    "helpUrl": ""
}, {
    "type": "dict_get",
    "message0": "获取字典 %1 %2 里 %3 属性的值",
    "args0": [
        {
            "type": "input_dummy"
        },
        {
            "type": "input_value",
            "name": "dict",
            "check": "dict"
        },
        {
            "type": "input_value",
            "name": "key",
            "check": "String"
        },
    ],
    "inputsInline": true,
    "output": null,
    "colour": "#a073ff",
    "tooltip": "获取属性的值。",
    "helpUrl": ""
}, {
    "type": "dict_copy",
    "message0": "复制字典 %1 %2 到 %3 %4 字典里。",
    "args0": [
        {
            "type": "input_dummy"
        },
        {
            "type": "input_value",
            "name": "target",
            "check": "dict"
        },
        {
            "type": "input_dummy"
        },
        {
            "type": "input_value",
            "name": "dict",
            "check": "dict"
        }
    ],
    "inputsInline": true,
    "previousStatement": null,
    "nextStatement": null,
    "colour": "#a073ff",
    "tooltip": "复制字典里的所有属性到另外一个字典里。",
    "helpUrl": ""
}, {
    "type": "dict_inc",
    "message0": "字典 %1 %2 里是否存在 %3 属性",
    "args0": [
        {
            "type": "input_dummy"
        },
        {
            "type": "input_value",
            "name": "dict",
            "check": "dict"
        },
        {
            "type": "input_value",
            "name": "key",
            "check": "String"
        },
    ],
    "inputsInline": true,
    "output": "Boolean",
    "colour": "#a073ff",
    "tooltip": "判断某个字典是否存在某个属性。",
    "helpUrl": ""
}, {
    "type": "dict_geto",
    "message0": "获取字典 %1 %2 的 %3",
    "args0": [
        {
            "type": "input_dummy"
        },
        {
            "type": "input_value",
            "name": "dict",
            "check": "dict"
        },
        {
            "type": "field_dropdown",
            "name": "option",
            "options": [
                [
                    "项数（数字）",
                    "length"
                ],
                [
                    "所有属性（列表）",
                    "keys"
                ],
                [
                    "所有值（列表）",
                    "values"
                ]
            ]
        }
    ],
    "inputsInline": true,
    "output": [
        "Number",
        "Array"
    ],
    "colour": "#a073ff",
    "tooltip": "获取字典的项数等数据。",
    "helpUrl": ""
}, {
    "type": "dict_delete",
    "message0": "删除字典 %1 %2 中的 %3 属性",
    "args0": [
        {
            "type": "input_dummy"
        },
        {
            "type": "input_value",
            "name": "dict",
            "check": "dict"
        },
        {
            "type": "input_value",
            "name": "key",
            "check": "String"
        },
    ],
    "inputsInline": true,
    "previousStatement": null,
    "nextStatement": null,
    "colour": "#a073ff",
    "tooltip": "删除字典的某个属性值",
    "helpUrl": ""
}, {
    "type": "dict_clear",
    "message0": "清空字典 %1",
    "args0": [
        {
            "type": "input_value",
            "name": "dict",
            "check": "dict"
        }
    ],
    "inputsInline": true,
    "previousStatement": null,
    "nextStatement": null,
    "colour": "#a073ff",
    "tooltip": "清空字典中所有的属性和值",
    "helpUrl": ""
}, {
    "type": "dict_is_empty",
    "message0": "字典 %1 是否为空",
    "args0": [
        {
            "type": "input_value",
            "name": "dict",
            "check": "dict"
        }
    ],
    "inputsInline": true,
    "output": "Boolean",
    "colour": "#a073ff",
    "tooltip": "查看某个字典是否为空。",
    "helpUrl": ""
}]);

Blockly.Python['dict_clear'] = function (block) {
    var value_dict = Blockly.Python.valueToCode(block, 'dict', Blockly.Python.ORDER_ATOMIC);
    var code = `${value_dict || "({})"}.clear()\n`;
    return code;
};
Blockly.Python['dict_null'] = function (block) {
    return ["dict()", Blockly.Python.ORDER_NONE];;
};
Blockly.Python['dict_is_empty'] = function (block) {
    var value_dict = Blockly.Python.valueToCode(block, 'dict', Blockly.Python.ORDER_ATOMIC);
    var code = `len(${value_dict || "({})"}) == 0`;
    return [code, Blockly.Python.ORDER_NONE];
};
Blockly.Python['dict_copy'] = function (block) {
    var value_target = Blockly.Python.valueToCode(block, 'target', Blockly.Python.ORDER_ATOMIC);
    var value_dict = Blockly.Python.valueToCode(block, 'dict', Blockly.Python.ORDER_ATOMIC);
    var code = `${value_dict || "{}"} = ${value_target || "({})"}.copy()\n`;
    return code;
};
Blockly.Python['dict_delete'] = function (block) {
    var value_dict = Blockly.Python.valueToCode(block, 'dict', Blockly.Python.ORDER_ATOMIC);
    var text_key = Blockly.Python.valueToCode(block, 'key', Blockly.Python.ORDER_ATOMIC);
    var code = `del ${value_dict || "({})"}[${text_key ? text_key : null}]\n`;
    return code;
};
Blockly.Python['dict_set'] = function (block) {
    var value_dict = Blockly.Python.valueToCode(block, 'dict', Blockly.Python.ORDER_ATOMIC);
    var text_key = Blockly.Python.valueToCode(block, 'key', Blockly.Python.ORDER_ATOMIC);
    var value_value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_ATOMIC);
    var code = `${value_dict || "({})"}[${text_key ? text_key : null}] = ${value_value ? value_value : null}\n`;
    return code;
};
Blockly.Python['dict_inc'] = function (block) {
    var value_dict = Blockly.Python.valueToCode(block, 'dict', Blockly.Python.ORDER_ATOMIC);
    var text_key = Blockly.Python.valueToCode(block, 'key', Blockly.Python.ORDER_ATOMIC);
    var code = `(${text_key} in ${value_dict || "({})"}.keys())`;
    return [code, Blockly.Python.ORDER_NONE];
};
Blockly.Python['dict_get'] = function (block) {
    var value_dict = Blockly.Python.valueToCode(block, 'dict', Blockly.Python.ORDER_ATOMIC);
    var text_key = Blockly.Python.valueToCode(block, 'key', Blockly.Python.ORDER_ATOMIC);
    var code = `${value_dict || "({})"}[${text_key ? text_key : null}]`;
    return [code, Blockly.Python.ORDER_NONE];
};
Blockly.Python['dict_geto'] = function (block) {
    var value_dict = Blockly.Python.valueToCode(block, 'dict', Blockly.Python.ORDER_ATOMIC);
    var dropdown_option = block.getFieldValue('option');
    if (dropdown_option == "length") {
        var code = `len(${value_dict || "{}"})`;
    } else {
        var code = `${value_dict || "({})"}.${dropdown_option}()`;
    }
    return [code, Blockly.Python.ORDER_NONE];
};
